<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>订单详情</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}" />
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">秒杀订单详情</div>
    <table class="table" id="order">
        <tr>
            <td>商品名称</td>
            <td id="goodsName" th:text="${goods.goodsName}" colspan="3"></td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="2"><img th:src="@{${goods.goodsImg}}" width="200" height="200" /></td>
        </tr>
        <tr>
            <td>订单价格</td>
            <td colspan="2" th:text="${order.goodsPrice}"></td>
        </tr>
        <tr>
            <td>下单时间</td>
            <td th:text="${#dates.format(order.createTime, 'yyyy-MM-dd HH:mm:ss')}" colspan="2"></td>
        </tr>
        <tr>
            <td>订单状态</td>
            <td >
                <span th:if="${order.status eq 0}">未支付</span>
                <span th:if="${order.status eq 1}">待发货</span>
                <span th:if="${order.status eq 2}">已发货</span>
                <span th:if="${order.status eq 3}">已收货</span>
                <span th:if="${order.status eq 4}">已完成</span>
                <span th:if="${order.status eq 5}">已退款</span>
            </td>
            <td>
                <button class="btn btn-primary btn-block" type="submit" id="payButton">立即支付</button>
            </td>
        </tr>
        <tr>
            <td>收货人</td>
            <td colspan="2">XXX  18012345678</td>
        </tr>
        <tr>
            <td>收货地址</td>
            <td colspan="2">上海市浦东区世纪大道</td>
        </tr>
    </table>
</div>
</body>
<script type="text/javascript">
    var orderId=[[${orderStatus}]];
    $(function () {
        if (orderId==0){
            layer.open({
                type: 0,
                title:"提示",
                content:"正在排队中......",
                area:['300px','300px'],
                shade: 0.8,
                shadeClose:false
            })
            getResult();
        }
    })

    function getResult() {
        $.ajax({
            URL: "/seckill/result",
            type:"get",
            data:{
                goodsId:[[${goods.id}]]
            },
            success:function (data) {
                if (data.code==200){
                    var result=data.obj;
                    if (result==-1){
                        layer.msg("对不起,秒杀失败");
                        window.location.href="/goods/toDetail?goodsId="+[[${goods.id}]]
                    }if (result==0){
                        setTimeout(function () {
                            getResult();
                        },100);
                    }else {
                        layer.confirm("恭喜您，秒杀成功!是否查看订单?",{btn:["确定","取消"]},
                            function () {
                                layer.close(index);
                            },
                            function () {
                                window.location.href="/goods/toDetail?goodsId="+[[${goods.id}]]
                            }
                        );
                    }
                }
            },
            error:function (){
                layer.msg("客户端请求失败")
            }
        })
    }
</script>
</html>